package com.yaoxuguang.concurrence.singletonAndThread.serialize;

import java.io.ObjectStreamException;
import java.io.Serializable;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.singletonAndThread.serialize
 * @Description: 序列化实现单例
 * @date 2018年12月25日18:03
 */
public class MyObject implements Serializable {
    private static final long serialVersionUID= 999L;
    private static class MyObjectHandler{
        private static final MyObject MY_OBJECT = new MyObject();
    }

    public MyObject() {
    }

    public static MyObject getObject(){
        return MyObjectHandler.MY_OBJECT;
    }

    protected Object readResolve() throws ObjectStreamException{
        System.out.println("调用了readResolve方法");
        return MyObjectHandler.MY_OBJECT;
    }
}
